package com.atguigu.tingshu.user.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WeChatMpConfig {

    @Autowired
    private WechatAccountConfig wechatAccountConfig;

    //手动配置一个wxMaService对象放入spring容器
    @Bean
    public WxMaService wxMaService(){
        //创建要服务的WxMaCofing对象
        // 创建微信小程序配置实例
        WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
        // 设置小程序的AppID
        wxMaConfig.setAppid(wechatAccountConfig.getAppId());
        // 设置小程序的AppSecret
        wxMaConfig.setSecret(wechatAccountConfig.getAppSecret());
        //创建对象
        WxMaServiceImpl wxMaService = new WxMaServiceImpl();
        //设置配置
        wxMaService.setWxMaConfig(wxMaConfig);
        //返回对象
        return wxMaService;
    }

}
